%matplotlib inline
import numpy as np
import matplotlib.pylab as plt
import scipy.stats as stat
import os
import sys
import subprocess
path = '/home/nico/Dropbox/scripts/'
sys.path.append(os.path.abspath(path))
from functions import ReadCords, ReadFile, Readlc, phase_LC_plot, grid, Do_IP_metric, var_non_regular
#0Ra 1Dec_1 2Nobs 3Ampl 4MeanKs 5MeanErr 6mag_Z 7er_Z 8mag_Y 9er_Y 10mag_J 11er_J 12mag_H 13er_H 14mag_Ks 15er_Ks
d046 = np.genfromtxt('/home/nico/Documentos/VVV_Tiles/Disk/d046/Catalogos/Ks_zyjhk_d046.cat', usecols=[0,1,10,12,14])
Ra46 = d046[:,0]
Dec46 = d046[:,1]
J46 = d046[:,2]
H46 = d046[:,3]
Ks46 = d046[:,4]
l46, b46 = ReadCords(Ra46,Dec46)
path='/home/nico/Documentos/VVV_Tiles/Disk/d046/IP'
cand = '197.4895118-62.9859461.lc'
Do_IP_metric(cand,path=path,Pmin=0.05,Pmax=4.0,Nperiods=3000000,Ncompo=4,factor=3, plot_lc=1,plot_per=1,plot_phase=1,size=(7,5))
#GLS
#0Ra 1Dec_1 2Nobs 3Ampl 4MeanKs 5MeanErr 6mag_Z 7er_Z 8mag_Y 9er_Y 10mag_J 11er_J 12mag_H 13er_H 14mag_Ks 15er_Ks
GLS = ReadFile('GLS_cand_visual_inspection_d046.cat',path='/home/nico/Documentos/VVV_Tiles/Disk/d046/Catalogos', ReadStr=True)
Ra_GLS = GLS[:,0]
Dec_GLS = GLS[:,1]
Period_GLS = GLS[:,8]
l_GLS, b_GLS = ReadCords(Ra_GLS,Dec_GLS)
#IP
IP = ReadFile('IP_cand_visual_inspection_d046.cat',path='/home/nico/Documentos/VVV_Tiles/Disk/d046/Catalogos', ReadStr=True)
Ra_IP = IP[:,0]
Dec_IP = IP[:,1]
Period_IP = IP[:,7]
l_IP, b_IP = ReadCords(Ra_IP,Dec_IP)
#Irregulares
Irr = ReadFile('Match_eta_DKs_d046.cat',path='/home/nico/Documentos/VVV_Tiles/Disk/d046/Catalogos', ReadStr=True)
Ra_Irr = Irr[:,0]
Dec_Irr = Irr[:,1]
l_Irr, b_Irr = ReadCords(Ra_Irr,Dec_Irr)
plt.plot(l_GLS, b_GLS,'ro',label='GLS')
plt.plot(l_IP, b_IP, 'g*',label='IP' )
plt.plot(l_Irr, b46_Irr,'bs',label='Irr')
plt.xlabel(r'${\rm Galactic\ Longuitude\ \ell\ [^{o}]}$',fontsize=15)
plt.ylabel(r'${\rm Galactic\ Latitude\ b\ [^{o}]}$',fontsize=15)
plt.gca().invert_xaxis()
lgd = plt.legend(loc='best',fontsize=20,bbox_to_anchor=(1,1))
gridsize=300
fontsize=20
plt.figure(figsize=(4,8))
plt.title('d046')
cmap = plt.get_cmap('Blues')
#sns.cubehelix_palette(start=0, light=1, as_cmap=True)
hb = plt.hexbin(J46-Ks46, Ks46, gridsize=gridsize,bins="log",cmap=cmap)
plt.xlabel(r'${\rm (J-K_{s})}$',fontsize=fontsize)
plt.ylabel(r"${\rm K_{s}}$ [mag]",fontsize=fontsize)
plt.yticks(fontsize=15)
plt.xticks(fontsize=15)
plt.xlim(-0.1,5.4)
plt.ylim(10.8,17.6)
cb = plt.colorbar(hb)
cb.set_label(r'${\rm Log(Nstars)}$',fontsize=fontsize)
cb.ax.tick_params(labelsize=15)
plt.gca().invert_yaxis()
plt.figure(figsize=(7,6))
X, Y, Z = grid(l46, b46, J46-Ks46, resX=800, resY=350)
contour_levels = np.arange(0, 5., 0.4)
cmap = 'coolwarm'
cs = plt.contourf(X,Y,Z,contour_levels, cmap=cmap)
plt.xlabel(r'${\rm Galactic\ Longuitude\ \ell\ [^{o}]}$',fontsize=15)
plt.ylabel(r'${\rm Galactic\ Latitude\ b\ [^{o}]}$',fontsize=15)
plt.gca().invert_xaxis()
cb = plt.colorbar(cs, orientation = 'horizontal',aspect=40,pad=0.1)
cb.set_label(r'${\rm J-K_{s}}$ [mag]',fontsize=10)
cb.ax.tick_params(labelsize=20)
plt.plot(l_GLS, b_GLS,'r^',label='GLS')
plt.plot(l_IP, b_IP, 'gs',label='IP' )
#plt.plot(l_Irr, b_Irr,'bs',label='Irr')
lgd = plt.legend(loc='best',fontsize=20,bbox_to_anchor=(1,1))
plt.show()
plt.figure(figsize=(7,6))
X, Y, Z = grid(l46, b46, J46-Ks46, resX=800, resY=350)
contour_levels = np.arange(0, 5., 0.4)
cmap = 'coolwarm'
cs = plt.contourf(X,Y,Z,contour_levels, cmap=cmap)
plt.xlabel(r'${\rm Galactic\ Longuitude\ \ell\ [^{o}]}$',fontsize=15)
plt.ylabel(r'${\rm Galactic\ Latitude\ b\ [^{o}]}$',fontsize=15)
plt.gca().invert_xaxis()
cb = plt.colorbar(cs, orientation = 'horizontal',aspect=40,pad=0.1)
cb.set_label(r'${\rm J-K_{s}}$ [mag]',fontsize=10)
cb.ax.tick_params(labelsize=20)
plt.plot(l_GLS, b46_GLS,'ro',label='GLS')
plt.plot(l_IP, b46_IP, 'g*',label='IP' )
plt.plot(l_Irr, b46_Irr,'bs',label='Irr')
lgd = plt.legend(loc='best',fontsize=20,bbox_to_anchor=(1,1))
plt.show()
GLS = ReadFile('GLS_cand_visual_inspection_d046.cat',path='/home/nico/Documentos/VVV_Tiles/Disk/d046/Catalogos', ReadStr=True)
RaGLS = GLS[:,0]
DecGLS = GLS[:,1]
CatGLS = GLS[:,2]
P_GLS = GLS[:,8]
#J46 = GLS[:,2]
#H46 = GLS[:,3]
#Ks46 = GLS[:,4]
#l46, b46 = ReadCords(Ra46,Dec46)
for i in range(len(RaGLS)):
path = '/home/nico/Documentos/VVV_Tiles/Disk/d046/GLS'
mjd,mag,err = Readlc(CatGLS[i], path=path)
p = P_GLS[i]
print '---------------------------------------------------------------------------------'
#print cat_path
print "Nombre del catálogo: ",CatGLS[i]
print "amplitud: %0.3f [mag] " %(max(mag)-min(mag))
print "N° épocas: ",len(mag)
print "Magnitud media: %0.3f [mag]" %np.mean(mag)
print "Periodo: %0.4f [dias]" %p
#print "Clase: ", Class
#chi2,fit_ampl=phase_LC_plot(mjd,mag,err,p,Nterms=2,mjd0=min(mjd))
plot_lc_phase(CatGLS[i], path, p, Nterms=3)
plt.show()
IP = ReadFile('IP_cand_visual_inspection_d046.cat',path='/home/nico/Documentos/VVV_Tiles/Disk/d046/Catalogos', ReadStr=True)
RaIP = IP[:,0]
DecIP = IP[:,1]
CatIP = IP[:,2]
P_IP = IP[:,7]
path = '/home/nico/Documentos/VVV_Tiles/Disk/d046/IP'
for i in range(len(RaIP)):
mjd,mag,err = Readlc(CatIP[i], path=path)
p = P_IP[i]
print '---------------------------------------------------------------------------------'
#print cat_path
print "Nombre del catálogo: ",CatIP[i]
print "amplitud: %0.3f [mag] " %(max(mag)-min(mag))
print "N° épocas: ",len(mag)
print "Magnitud media: %0.3f [mag]" %np.mean(mag)
print "Periodo: %0.4f [dias]" %p
#print "Clase: ", Class
#chi2,fit_ampl=phase_LC_plot(mjd,mag,err,p,Nterms=2,mjd0=min(mjd))
plot_lc_phase(CatIP[i], path, p, Nterms=4)
#Do_IP_metric(CatIP[i],path=path,Pmin=0.05,Pmax=6.0,Nperiods=500000,Ncompo=4,factor=3, plot_lc=1,plot_per=1,plot_phase=1,size=(7,5))
plt.show()
#Irregulares
Irr = ReadFile('Match_eta_DKs_d046.cat',path='/home/nico/Documentos/VVV_Tiles/Disk/d046/Catalogos', ReadStr=True)
Ra_Irr = Irr[:,0]
Dec_Irr = Irr[:,1]
Cat_Irr = Irr[:,2]
l_Irr, b_Irr = ReadCords(Ra_Irr,Dec_Irr)
path = '/home/nico/Documentos/VVV_Tiles/Disk/d046/lc'
for i in range(len(Ra_Irr)):
mjd,mag,err = Readlc(Cat_Irr[i], path=path)
print '---------------------------------------------------------------------------------'
#print cat_path
print "Nombre del catálogo: ",Cat_Irr[i]
print "amplitud: %0.3f [mag] " %(max(mag)-min(mag))
print "N° épocas: ",len(mag)
print "Magnitud media: %0.3f [mag]" %np.mean(mag)
#print "Clase: ", Class
var_non_regular(mjd,mag,err,size=(8,2.5),name=None,ms=10,mjd0=None)
plt.show()